package day03;

import java.util.concurrent.Flow;

public class MainTest {

    public static void main(String[] args) {
        // jdk9 之后支持的
        Flow.Publisher<String> publisher = subscriber -> {
            subscriber.onNext("1");
            subscriber.onNext("2");
            subscriber.onComplete();
        };

        publisher.subscribe(new Flow.Subscriber<>() {
            @Override
            public void onSubscribe(Flow.Subscription subscription) {
                subscription.request(1);
            }

            @Override
            public void onNext(String item) {
                System.out.println("接收：" + item);
            }

            @Override
            public void onError(Throwable throwable) {
                System.out.println("报错：" + throwable.getMessage());
            }

            @Override
            public void onComplete() {
                System.out.println("完成");
            }
        });

    }

}
